import 'package:flutter/material.dart';
import 'package:flutter/animation.dart';

class TabBarPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return TabBarState();
  }
}

class TabBarState extends State<TabBarPage>
    with SingleTickerProviderStateMixin {
  List<String> favorites = ['电影', '美食', '音乐', '历史', '化学', '百度'];

  TabController _tabController;


  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: favorites.length, vsync: this);

  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return _buildTabBar();
  }

  Widget _buildTabBar() {
    return Column(
      mainAxisSize: MainAxisSize.max,
      children: <Widget>[
        TabBar(
            isScrollable: true,
            tabs: favorites.map((e) => Text(e)).toList(),
            controller: _tabController,
            labelColor: Color(0xFFBA68C8),
            unselectedLabelColor: Colors.black,
            indicatorColor: Color(0xFFAA68C8),
            indicatorWeight: 2),
        Expanded(
          child: Container(
            child: TabBarView(
                controller: _tabController,
                children: favorites
                    .map((e) => Center(child: Text(e + '内容')))
                    .toList()),
          ),
        )
      ],
    );
  }
}
